/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * Description:
 * Author: huawei
 * Create: 2023-07-25
 */

/* Should only be included by devmm_adapt.h */

#ifndef SVM_HOST_ADAPT_H
#define SVM_HOST_ADAPT_H

#include <linux/mm.h>
#include <linux/hugetlb.h>
#include <linux/gfp.h>

#include <securec.h>

#include "svm_cmd.h"

#ifndef HUGETLB_ALLOC_NONE
#define HUGETLB_ALLOC_NONE             0x00
#endif
#ifndef HUGETLB_ALLOC_NORMAL
#define HUGETLB_ALLOC_NORMAL           0x01
#endif
#ifndef HUGETLB_ALLOC_BUDDY
#define HUGETLB_ALLOC_BUDDY            0x02
#endif
#ifndef HUGETLB_ALLOC_NORECLAIM
#define HUGETLB_ALLOC_NORECLAIM        0x04
#endif

#ifndef __GFP_ACCOUNT
#ifdef __GFP_KMEMCG
#define __GFP_ACCOUNT __GFP_KMEMCG /* for linux version 3.10 */
#endif
#ifdef __GFP_NOACCOUNT
#define __GFP_ACCOUNT 0            /* for linux version 4.1 */
#endif
#endif

static inline bool devmm_is_cdm_node(int nid)
{
    return false;
}

static inline u32 devmm_get_alloc_mask(void)
{
    /* arm host can not use __GFP_THISNODE flag */
    return (u32)(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN | __GFP_ACCOUNT);
}

static inline int devmm_get_nids(u32 devid, u32 vfid, u32 mem_type, int nids[], u32 *nid_num)
{
    *nid_num = 1;
    nids[0] = NUMA_NO_NODE;
    return 0;
}

static inline u32 devmm_get_hugetlb_alloc_flag(struct page *hpage)
{
    return 0;
}

static inline struct page *_devmm_alloc_hpage(int nid, u32 flag)
{
    return NULL;
}

#endif /* SVM_HOST_ADAPT_H */

